package com.atguigu.gulimall.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池初始化类
 *
 * @author xiaoping
 * @create 2020/5/27 18:23
 * @since 1.0.0
 */
@Configuration
public class MyThreadConfig {

    /**
     * corePoolSize         核心线程数
     * maximumPoolSize      最大线程数
     * keepAliveTime        存活时间
     * unit                 时间单位
     * workQueue            阻塞队列
     * threadFactory        线程工厂
     * handler              拒绝策略
     * @return
     */
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
       return new ThreadPoolExecutor(pool.getCoreSize(), pool.getMaxSize(), pool.getKeepAliveTime(), TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
